package com.wyd.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class restfulcontroller {

    @RequestMapping("/add/{p1}/{p2}")
    public String add(@PathVariable int p1, @PathVariable int p2, Model model){
        int result = p1 + p2;
        model.addAttribute("msg","结果为："+result);
        return "test1";
    }

    @RequestMapping("/sub/{p1}/{p2}")
    public String subtraction(@PathVariable int p1,@PathVariable int p2,Model model){
        int result = 0;
        result = p1 - p2;
        model.addAttribute("msg","结果为："+result);
        return "test1";
    }

    @RequestMapping("/mut/{p1}/{p2}")
    public String multiplication(@PathVariable int p1,@PathVariable int p2,Model model){
        int result = p1 * p2;
        model.addAttribute("msg","结果为："+result);
        return "test1";
    }

    @RequestMapping("/div/{p1}/{p2}")
    public String division(@PathVariable int p1,@PathVariable int p2,Model model){
        int result = 0;
        if(p2==0){
            model.addAttribute("msg","除数为0，非法计算");
        }else{
            result = p1/p2;
            model.addAttribute("msg","结果为："+result);
        }
        return "test1";
    }
}
